"""
计算一组股票一段时间的收益率
"""
import argparse
from AStock.ASAnalysis import ASEarningRatio, ASIndexChangeRatio


def _main_(args):
    codes = args.stock_codes
    begin_date = args.begin_date
    end_date = args.end_date
    sort = args.sort
    # TODO 权重暂未考虑
    # weights = args.weights

    # if weights and len(weights) != len(codes):
    #     print('codes and weights not match')
    #   return
    er = ASEarningRatio(codes, begin_date, end_date)
    er.run(sort=sort)

    icr = ASIndexChangeRatio(begin_date, end_date)
    icr.run()


if __name__ == '__main__':
    argparser = argparse.ArgumentParser(description='calculate earning ratio of given stocks and dates')
    argparser.add_argument('-b', '--begin-date', required=True, help='begin date, yyyymmdd format')
    argparser.add_argument('-e', '--end-date', required=True, help='begin date, yyyymmdd format')
    argparser.add_argument('-s', '--stock-codes', nargs='+', help='stock codes')
    argparser.add_argument('-t', '--sort', required=False, action='store_true',
                           default=False, help='sort by earning ratio')

    args = argparser.parse_args()
    _main_(args)
